var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

require('./database/connect')  //引入数据库链接文件
let cors = require('cors')
app.use(cors())
app.use(logger('dev'));
app.use(express.json());    //body数据处理
app.use(express.urlencoded({ extended: false }));   //body数据处理
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));    //静态资源托管

app.use('/', indexRouter);
app.use('/users', usersRouter);

module.exports = app;
